package com.simon.webflux.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.WebClient;

@Configuration
public class HttpInterfaceConfiguration {

    @Bean
    public WebClient webClient() {
        WebClient client = WebClient.builder()
                .filter((request, next) -> next.exchange(createFiltered(request)))
                .build();
        return client;
    }

    private ClientRequest createFiltered(ClientRequest request) {
        // 自定义过滤器
        ClientRequest filtered = ClientRequest.from(request)
                .header("foo", "bar")
                .build();
        return filtered;
    }

}
